package com.yunchen.BooksManagementSystem.manage.servlet;

import com.alibaba.fastjson.JSON;
import com.yunchen.BooksManagementSystem.manage.dao.adminDaoImpl;
import com.yunchen.BooksManagementSystem.manage.entity.borrowingRecord;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

@WebServlet(name = "UserApplyServlet", value = "/UserApplyServlet")
public class UserBorrowApplyServlet extends HttpServlet {
    private adminDaoImpl ad=new adminDaoImpl();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<borrowingRecord> br=null;
        try {
            br=ad.userBorrowApply();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        String jsonString= JSON.toJSONString(br);
        response.setContentType("text/json;charset=UTF-8");
        response.getWriter().write(jsonString);

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}
